package com.dkd.day20250619;
import com.dkd.day20250616.TreeNode;

public class SolutionConvert {
    public static void main(String[] args) {

    }
    public TreeNode head = null;
    public TreeNode pre = null;

    public TreeNode Convert(TreeNode pRootOfTree) {
        if(pRootOfTree == null) return null;
        Convert(pRootOfTree.left);
        //找到最小值，初始化
        if(pre == null){
            head =pRootOfTree;
            pre = pRootOfTree;
        }
        //当前节点与上一节点建立链接，将pre设置为当前值
        else{
            pre.right = pRootOfTree;
            pRootOfTree.left = pre;
            pre = pRootOfTree;
        }
        //遍历右子树
        Convert(pRootOfTree.right);
        return head;
    }
}
